#include "testunitaire.h"

extern char bufferHigh[256];
extern char bufferLow[256];

/*! \note Test unitaire de la carte SD */
boolean testInitSd()
{
    SD_STATUS statut = sd_init();
    if (statut == SD_STATUS_VALID)
        return true;
    else
        return false;
}

boolean testSectorRead512()
{
    SD_STATUS statut = sd_sector_read512(0, bufferHigh, bufferLow);
    if (statut == SD_STATUS_VALID)
        return true;
    else
        return false;
}

boolean testSectorWrite512()
{
    SD_STATUS statut = sd_sector_write512(0, bufferHigh, bufferLow);
    if (statut == SD_STATUS_VALID)
        return true;
    else
        return false;
}

boolean testSDDetect()
{
    if (sd_detect())
        return true;
    else
        return false;
}

boolean testGetCSD()
{
    char buffer[20];
    SD_STATUS statut = sd_get_csd(buffer);
    if (statut == SD_STATUS_VALID)
        return true;
    else
        return false;
}

boolean testGetCID()
{
    char buffer[20];
    SD_STATUS statut = sd_get_cid(buffer);
    if (statut == SD_STATUS_VALID)
        return true;
    else
        return false;
}

boolean testAddMeasure()
{
    char buffer[20];
    SD_STATUS statut = add_measure(buffer, 20);
    if (statut == SD_STATUS_VALID)
        return true;
    else
        return false;
}

boolean testWritePointer()
{
    SD_STATUS statut = write_pointer(1, 25, 32);
    if (statut == SD_STATUS_VALID)
        return true;
    else
        return false;
}

boolean testReadPointer()
{
    long sector;
    int byteH, byteL;
    SD_STATUS statut = read_pointer(&sector, &byteH, &byteL);
    if (statut == SD_STATUS_VALID && sector == 1 && byteH == 25 && byteL == 32)
        return true;
    else
        return false;
}

boolean testErasePointer()
{
    long sector;
    int byteH, byteL;
    SD_STATUS statut, statut2;
    statut = erase_pointer();
    statut2 = read_pointer(&sector, &byteH, &byteL);
    if (statut == SD_STATUS_VALID && statut2 == SD_STATUS_VALID && sector == 1 && byteH == 0 && byteL == 0)
        return true;
    else
        return false;
}

boolean testReadState()
{
    long status;
    SD_STATUS statut = read_state(&status);
    if (statut == SD_STATUS_VALID)
        return true;
    else
        return false;
}

boolean testSizeOfCard()
{
    long size = sizeOfCard();
    if (size != 0)
        return true;
    else
        return false;
}

/*! \note Test unitaire du module GSM */
boolean testSendSMS()
{
    char rep[9];
    char repAttendue[9] = "+CMGS: 13";
    char dest[12] = "\"0630330554\"";
    char data[13] ="Test envoiSMS";
    int sizeData = 13;
    sendSMS(dest,data, sizeData);

    ReceptionUSART2(rep, 1);

    if (strcmp(rep, repAttendue) == 0)
        return true;
    else
        return false;
}

boolean testGetTime()
{
    char Reponse_Date[25];
    char date_gsm[25];

    getTime(date_gsm) ;

    if (strlen(date_gsm) == 25)
        return true;
    else
        return false;
}

boolean testGetGSMReseau()

{
    int reseau = get_GSM_RESEAU();

    if (reseau != 0)
        return true;
    else
        return false;
}



